package group2assignone.ucm.manager;

import group2assignone.dao.MyDAO;
import group2assignone.model.Flight;
import group2assignone.ucm.UCController;
import group2assignone.ucm.UCStartup;
import group2assignone.view.manager.DeleteFlightView;

/**
 * use case to update view for deleting a flight
 * @author group2
 */
public class UCDeleteFlightSearch implements UCController {

    private DeleteFlightView deleteView = new DeleteFlightView();
    private Flight f = new Flight();

    /**
     * sets view and flight
     * @param dView
     * @param fl
     */
    public UCDeleteFlightSearch(DeleteFlightView dView, Flight fl) {
        deleteView = dView;
        f = fl;
    }

    @Override
    public void run() {
        //Search database for flight number
        //returns flight
        MyDAO coms = UCStartup.getInstance().getDAO();
        f = coms.sQLGetFlight(deleteView.getFlightNum());

        if (f.getFlightNum().equals(null)) //if flight doesn't exist
        {
            deleteView.resetFlightNum();
            deleteView.errorFlightNum(); //show error message
        } else {
            deleteView.showFlightDetails(f); //else display details
        }
    }
}
